package zuosheng.lianbiao;

import java.util.Stack;

/**
 * @author lj
 * @Description: 删除指定值的节点
 * @date 2020-11-15 11:05
 * @QQ 851477108
 */


public class remove {
    public class Node{
        public int value;
        public Node next;
        public Node(int data){
            this.value = data;
        }
    }

    public Node removeList(Node head, int num){
        Stack<Node> stack = new Stack<>();
        while (head != null){
            if (head.value != num){
                stack.push(head);
            }
            head = head.next;
        }
        while (!stack.isEmpty()){
            stack.peek().next = head;
            head = stack.pop();
        }
        return head;
    }
}
